package com.huakang.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huakang.entity.Nurse;
import com.huakang.service.DocterService;
import com.huakang.service.NurseService;
import com.huakang.utils.DocterVo;
import com.huakang.utils.NurseVo;
import com.huakang.utils.ResultVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author{小熊}
 * @Date2025/1/10 22:52
 */
@RestController
@RequestMapping("/nurse")
public class NurseController {

    @Autowired
    private NurseService nurseService;

    @GetMapping("/getAll")
    public ResultVo getAll(@RequestParam(defaultValue = "1")Integer pageNum , @RequestParam(defaultValue = "5")Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<NurseVo> list = nurseService.getAll();
        PageInfo<NurseVo> pageInfo = new PageInfo<>(list);
        return ResultVo.success("查询成功",pageInfo);
    }
    @GetMapping("/getByCondition")
    public ResultVo getByCondition(@Param("nname") String nname, @Param("dename") String dename, @Param("kname") String kname){
       List<NurseVo> list =  nurseService.getByCondition(nname,dename,kname);
       if(list.size() == 0){
           return ResultVo.fail("未查询到数据");
       }
       return ResultVo.success("查询成功",list);
    }

    @DeleteMapping("/delete")
    public ResultVo delete(Integer nid){
        boolean flag = nurseService.delete(nid);
        if(flag){
            return ResultVo.success("删除成功");
        }
        return ResultVo.fail("删除失败");
    }
    @PostMapping("/add")
    public ResultVo add(@RequestBody Nurse nurse){
       boolean flag = nurseService.add(nurse);
       if(flag){
           return ResultVo.success("添加成功");
       }
       return ResultVo.fail("添加失败");
    }
    @GetMapping("/getById")
    public ResultVo getById(Integer nid){
        Nurse nurse = nurseService.getById(nid);
        return ResultVo.success("查询成功",nurse);
    }
    @PutMapping("/update")
    public ResultVo update(@RequestBody Nurse nurse){
        boolean flag = nurseService.update(nurse);
        if(flag){
            return ResultVo.success("修改成功");
        }
        return ResultVo.fail("修改失败");
    }

}
